package middleware

import (
	"github.com/gofiber/fiber/v3"
	"log"
)

func Logger(logCtx string) func(c fiber.Ctx) error {
	return newFilter(func() {
		log.Print(logCtx)
	})
}

func newFilter(handler func()) func(c fiber.Ctx) error {
	return func(c fiber.Ctx) error {
		handler()
		return c.Next()
	}
}

func newFilterWithError(handler func() error) func(c fiber.Ctx) error {
	return func(c fiber.Ctx) error {
		if err := handler(); err != nil {
			return err
		}
		return c.Next()
	}
}
